<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>用户</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!-- 公共样式 开始 -->
		<link rel="stylesheet" type="text/css" href="css/base.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont.css">
		<script type="text/javascript" src="framework/jquery-1.11.3.min.js"></script>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css">
		<script type="text/javascript" src="layui/layui.js"></script>
		<!-- 滚动条插件 -->
		<link rel="stylesheet" type="text/css" href="css/jquery.mCustomScrollbar.css">
		<script src="framework/jquery-ui-1.10.4.min.js"></script>
		<script src="framework/jquery.mousewheel.min.js"></script>
		<script src="framework/jquery.mCustomScrollbar.min.js"></script>
		<script src="framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
		<script src="layui/layui.js"></script>
		<script src="./js/loadselect.js" charset="utf-8"></script>
	<!-- 公共样式 结束 -->
  </head>
  
  <body>
			<div class="">
			<div class="layui-row layui-col-space10">
				<form class="layui-form" action="">
			  		<div class="layui-form-item">
			  		<br>
				      	<div class="layui-input-inline">
							<input style="width:200px;" type="text" name="price"class="layui-input" id="departmentselecet" placeholder="请输入用户名称">
						</div>
						<div class="layui-input-inline">
							<input style="width:200px;" type="text" name="price"class="layui-input" id="departmentselecet2" placeholder="请输入角色名称">
						</div>
						<div class="layui-inline">
							<button id="btnselbackdepart" type="button"class="layui-btn layuiadmin-btn-useradmin layui-btn-radius">查询</button>
						</div>
						<div class="layui-inline">
							<button class="layui-btn layuiadmin-btn-useradmin layui-btn-radius" type="button" id="btn_adduser">添加</button>
						</div>
			  		</div> 
			  	</form>
			</div>
		<table class="layui-hide" id="Userlist" lay-filter="Userlist"></table>
		<script type="text/html" id="barDemo"> 
				  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
				  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
       
		<script type="text/html" id="selectbar">
				<input type="checkbox" name="{{d.deepth}}" value="{{d.id}}" title="授予" lay-filter="lockDemo" {{ d.isedit == "1" ? 'checked' : '' }}>
		</script>

		<script type="text/html" id="menuTypebar">
				<span>{{ d.deepth <= "1" ? '展开菜单' : '子菜单' }}</span>
		</script>

	</div>

	<!--弹窗内容用户添加 -->
	<div id="div_adduser" style="display: none;text-align: center; ">
		<form class="layui-form" action="">
				<div class="layui-col-md6">
				<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">用户编号</label>
						<div class="layui-input-inline">
							<input type="text" id="userid" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
				   
					<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">用户名</label>
						<div class="layui-input-inline">
							<input type="text" id="username" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">真实姓名</label>
						<div class="layui-input-inline">
							<input type="text" id="realname" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">联系电话</label>
						<div class="layui-input-inline">
							<input type="text" id="phone" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">部门编号</label>
						<div class="layui-input-inline">
							<input type="text" id="departmentid" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-col-md6">
				
					<div class="layui-form-item">
						<label class="layui-form-label"style="width:100px;">备注</label>
						<div class="layui-input-inline">
							<input type="text" id="note" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					 <div class="layui-form-item">
				      <label class="layui-form-label" style="width:100px;">用户类型:</label>
				      <div class="layui-input-inline">
				       	<select id="userRole">
						  <option value="00">请选择用户类型</option>
						</select> 
				      </div>
				    </div>
				</div>
				
				<div class="layui-form-item">
						<button class="layui-btn" lay-submit lay-filter="submitBut" id="btn_User">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
		</form>
	</div>
	<script src="framework/area.js"></script>
	<script type="text/javascript" src="js/md5.js"></script>
	<script src="framework/province.js"></script>
	<script src="./js/loadselect.js" charset="utf-8"></script>
	<script src="js/Bookkeep.js"></script>
	<script>
//查询开始
layui.use([ 'table', 'form', 'layer',  'laytpl', 'element' ], function() {
		var table = layui.table, form = layui.form, 
			layer = layui.layer, $ = layui.jquery,
			element = layui.element;
			
		/*加载表格*/
		table.render({
			elem : '#Userlist',
			id:'Userlist',
			url : './user/getuserlist',
			title : '',
			height : "full-160",
			skin : 'line',
			curr:1,
			even : true,
			cols: [
			[ 
			{
				field: 'username',
				align: 'center',
				title: '用户名'						
			} ,
			{
				field: 'realname',
				align: 'center',
				title: '真实姓名'						
			} ,
			{
				field: 'rolename',
				align: 'center',
				title: '用户角色'						
			} ,
			{
				field: 'phone',
				align: 'center',
				title: '联系电话'						
			},
			{
				field: 'status',
				align: 'center',
				title: '状态'						
			},
			{
				field: 'lastlogindate',
				align: 'center',
				title: '最后登录时间'						
			},
			{
				field: 'createtime',
				align: 'center',
				title: '创建时间'						
			},
			{
				field: 'departmentid',
				align: 'center',
				title: '部门编号'						
			},
			{
				field: 'note',
				align: 'center',
				title: '备注'						
			},
			 {
						title: '操作',
						toolbar: '#barDemo',
						align: 'center',
						width : 180
					}] 
			 ],
			page: {
					layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
					groups: 5,
					limit: 10,
					limits: [10, 20, 30, 40, 50],
					theme: '#1E9FFF',						
			 }
		});
		
		//条件查询
		$("#btnselbackdepart").click(function(){
   		var departmentselecet=$("#departmentselecet").val().trim();
   		var departmentselecet2=$("#departmentselecet2").val().trim();
   		var param = "?realname="+departmentselecet+"&rolename="+departmentselecet2;
   		alert(param);
   		table.render({
			elem : '#Userlist',
			id:'Userlist',
			url : './user/getuserlist' + param,
			title : '',
			height : "full-160",
			skin : 'line',
			curr:1,
			even : true,
			cols: [
			[ 
			{
				field: 'username',
				align: 'center',
				title: '用户名'						
			} ,
			{
				field: 'realname',
				align: 'center',
				title: '真实姓名'						
			} ,
			{
				field: 'rolename',
				align: 'center',
				title: '用户角色'						
			} ,
			{
				field: 'phone',
				align: 'center',
				title: '联系电话'						
			},
			{
				field: 'status',
				align: 'center',
				title: '状态'						
			},
			{
				field: 'lastlogindate',
				align: 'center',
				title: '最后登录时间'						
			},
			{
				field: 'createtime',
				align: 'center',
				title: '创建时间'						
			},
			{
				field: 'departmentid',
				align: 'center',
				title: '部门编号'						
			},
			{
				field: 'note',
				align: 'center',
				title: '备注'						
			},
			{
				field: 'isedit',
				align: 'center',
				title: '操作',
				toolbar : '#barDemo'
			}]
			],
			page: {
					layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
					groups: 5,
					limit: 10,
					limits: [10, 20, 30, 40, 50],
					theme: '#1E9FFF',						
			 }
			});
   		});
   		table.on('tool(Userlist)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event;
		  //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		  var tr = obj.tr; //获得当前行 tr 的DOM对象
		  if(layEvent == 'del'){ //删除
		    layer.confirm('真的删除行么', function(index){
		      obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
		      layer.close(index);
		      //向服务端发送删除指令
		      	$.post("role/deleterole",{roleid:obj.data.roleid},function(flag){
	    			if(flag){
	    				layer.msg("刪除成功",{icon:6}); //表格刷新
				        table.reload('Userlist'); //重载表格	
	    			}else{
	    				layer.msg("刪除失敗",{icon:5});
	    			}
		    	});
		    });
		   } else if(layEvent == 'edit'){ //编辑
		    //do something
		   //脚本编辑弹出层
	             var name = encodeURIComponent(data.toolName);
	             //alert(name);
	             layer.open({
		               type: 2,
		               title: '修改信息',
		               shadeClose: true,
		               shade: 0.5,
		               closeBtn:'1',//右上角xx关闭
		               area: ['500px','500px'],
		               content:'edit_User.jsp',
		               btn: ['确定', '取消'],
		               yes: function(index, layero){
			           //点击确认触发 iframe 内容中的按钮提交
			           var submit = layero.find('iframe').contents().find("#btn_update");
			           submit.click();
			           //表格刷新
		          	   table.reload('Userlist');
			        },
		               success : function(layero, index){
				            var body = layui.layer.getChildFrame('body', index);
				            if(layEvent == 'edit'){
				                // 取到弹出层里的元素，并把编辑的内容放进去
				                body.find("#Roleid").val(obj.data.roleid);  //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
				                body.find("#Rolename").val(obj.data.rolename); 
				                body.find("#description").val(obj.data.description);
				                body.find("#createtime").val(obj.data.createtime);
				                body.find("#deepth").val(obj.data.deepth);
				                 body.find("#parentid").val(obj.data.parentid);
				                // 记得重新渲染表单
		                		form.render();
				            }
				            setTimeout(function(){
				                layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
				                    tips: 3
				                });
				            },100)
				        }
	             });
	              //同步更新缓存对应的值
		    obj.update({
		      username: '123'
		      ,title: 'xxx'
		    });
		  }
		});		
	//查询结束
		
			//添加一条方法开始
	$("#btn_User").click(function(){
			//获取
			var userid=$("#userid").val();
					var username=$("#username").val();
					var realname=$("#realname").val();
					var phone=$("#phone").val();	
					var departmentid=$("#departmentid").val();	
					var note=$("#note").val();	
					var pwd = 000000;
					var userRole = $("#userRole").val();
					var enpwd = hex_md5(fix(userid,pwd));	
		//构建参数 
					var obj = {
						"userid":userid,
						"username":username,
						"pwd":enpwd,
						"realname":realname,
						"phone":phone,
						"departmentid":departmentid,
						"note":note,
						"Roleid":userRole
					}
			$.ajax({
					url : 'user/adduser',
					type : "POST",
					data : obj, //直接传对象参数 
					dataType : 'json',
					success : function(data) {
							alert("添加成功!");
					},
					error:function(){
	    	        	$("#input").val("");
	    	        }  
			});
		});
	});
				
		//添加结束
		

  </script>

</body>
</html>
